<template>
  <div class="bottom" @touchmove="moveScroll" ref="music-list">
    <!-- 播放信息 -->
    <div class="play-info" v-if="count != -1">
      <div class="left" @click="playAll">
        <i class="iconfont icon-bofang"></i>
        <div class="play-all">
          播放全部<span>(共{{ data.length }}首)</span>
        </div>
      </div>
      <div class="right" v-if="count != 0">
        <i class="iconfont icon-tianjia"></i>
        收藏({{ count | totalFor }})
      </div>
    </div>
    <!-- 歌曲列表 -->
    <ul class="music-list">
      <li
        v-for="(item, index) in data"
        :key="item.id"
        @click="playMusic(index)"
        @touchstart="songFly"
      >
        <span>{{ index + 1 }}</span>
        <div class="music-info">
          <div class="t1">{{ item.title }}</div>
          <div class="t2">
            <span v-for="name in item.ar" :key="name">
              {{ name }}
            </span>
            <i>-</i>
            {{ item.al.name }}
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import $ from "jquery";
export default {
  props: {
    data: Array, //音乐数据
    showTitle: Boolean,
    count: {
      type: Number,
      default: 1, //等于0时隐藏收藏,-1时隐藏播放全部,以及搜索当前歌曲
    },
  },
  mounted() {},
  methods: {
    moveScroll() {
      let flag = $(".page").scrollTop() > 150 ? true : false;
      this.$emit("update:showTitle", flag);
    },
    async playMusic(i) {
      if (this.count == -1) {
        this.$store.dispatch("search/getSearchDetail", {
          ids: this.data[i].id,
        });
        // this.$store.dispatch("player/getLyric");
      } else {
        //设置歌曲播放列表
        this.$store.commit("player/setPlaySongList", this.data);
        //设置歌曲播放的下标
        this.$store.commit("player/setCurrentIndex", i);
        // 获取播放歌词
        this.$store.dispatch("player/getLyric");
      }
      //设置歌曲播放
      this.$store.commit("player/setPlaying", true);
    },
    playAll() {
      this.$store.commit("player/setPlaySongList", this.data);
      this.$store.commit("player/setCurrentIndex", 0);
      this.$store.dispatch("player/getLyric");
      this.$store.commit("player/setPlaying", true);
    },
    songFly({ changedTouches }) {
      //   $('i').remove('.music-fly')
      //   let e=changedTouches[0]
      //   let x=e.pageX
      //   let y=e.pageY
      //  $(this.$refs['music-list']).append(`<i class='music-fly iconfont icon-icon-'></i>`)
      //  $('.music-fly').css({
      //    position:'absolute',
      //    top:y,
      //    left:x,
      //    fontSize:'20px',
      //    color:'#f40'
      //  }).animate({
      //    marginTop:'-30px',
      //    marginLeft:'-20px'
      //  },200).animate({
      //    top:'100%'
      //  },600)
    },
  },
};
</script>
<style lang="scss" scoped>
.music-fly {
  position: absolute;
  transform: translateY();
  top: 0;
  left: 50px;
}
</style>
<style lang="scss" scoped>
@import "../../assets/global-style.scss";
.bottom {
  padding-bottom: 60px;
  background: #fff;
  border-radius: 7px;
  .play-info {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid $border-color;
    .left {
      margin-left: 5px;
      display: flex;
      align-items: center;
      i {
        font-size: 20px;
      }
      .play-all {
        font-size: 16px;
        margin-left: 10px;
        span {
          font-size: 12px;
          color: $font-color-desc-v2;
          margin-left: 5px;
        }
      }
    }
    .right {
      height: 100%;
      background: $theme-color;
      padding: 0 30px 0 10px;
      border-radius: 3px;
      display: flex;
      align-items: center;
      color: $font-color-light;
      font-size: 14px;
      i {
        font-size: 14px;
        margin-right: 5px;
      }
    }
  }
  .music-list {
    li {
      height: 60px;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      span {
        width: 60px;
        text-align: center;
        font-size: 16px;
      }
      .music-info {
        flex: 1;
        height: 60px;
        padding: 5px 0;
        box-sizing: border-box;
        border-bottom: 1px solid $border-color;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        .t1,
        .t2 {
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          width: 320px;
        }
        .t1 {
          font-size: 16px;
        }
        .t2 {
          font-size: 12px;
          span {
            font-size: 12px;
          }
          color: $font-color-desc-v2;
        }
      }
    }
  }
}
</style>
